dnl SPDX-License-Identifier: GPL-2.0-only
AC_PREREQ([2.64])
AC_INIT([lttng-tools],[2.14.0-pre],[jeremie.galarneau@efficios.com],[],[https://lttng.org])

AC_CONFIG_HEADERS([include/config.h])
AC_CONFIG_AUX_DIR([config])
AC_CONFIG_MACRO_DIR([m4])

AC_CANONICAL_TARGET
AC_CANONICAL_HOST

AM_INIT_AUTOMAKE([1.12 foreign dist-bzip2 no-dist-gzip tar-pax nostdinc])
AM_MAINTAINER_MODE([enable])

# Enable silent rules if available (Introduced in AM 1.11)
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])


##                   ##
## C compiler checks ##
##                   ##

# Choose the C compiler
AC_PROG_CC
# AC_PROG_CC_STDC was merged in AC_PROG_CC in autoconf 2.70
m4_version_prereq([2.70], [], [AC_PROG_CC_STDC])

# Make sure the C compiler supports C99
AS_IF([test "$ac_cv_prog_cc_c99" = "no"], [AC_MSG_ERROR([The compiler does not support C99])])

# Enable available system extensions and LFS support
AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE

# Make sure the C compiler supports __attribute__
AX_C___ATTRIBUTE__
AS_IF([test "x$ax_cv___attribute__" != "xyes"],
  [AC_MSG_ERROR([The compiler does not support __attribute__ extensions])])

# Make sure we have pthread support
AX_PTHREAD([], [AC_MSG_ERROR([Could not configure pthread support])])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_INLINE
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UID_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T

# Detect warning flags supported by the C and C++ compilers and append them to
# WARN_CFLAGS and WARN_CXXFLAGS.
m4_define([WARN_FLAGS_COMMON_LIST], [ dnl
  -Wall dnl
  -Wextra dnl
  -Wmissing-declarations dnl
  -Wnull-dereference dnl
  -Wundef dnl
  -Wredundant-decls dnl
  -Wshadow dnl
  -Wsuggest-attribute=format dnl
  -Wtautological-constant-out-of-range-compare dnl Clang specific
  -Wwrite-strings dnl
  -Wformat=2 dnl
  -Wstrict-aliasing dnl
  -Wmissing-noreturn dnl
  -Wduplicated-cond dnl
  -Wduplicated-branches dnl
  -Wlogical-op dnl
  -Winit-self dnl
  dnl We currently get this warning when building with Clang:
  dnl
  dnl /usr/include/setjmp.h:54:12: error: declaration of built-in function '__sigsetjmp' requires the declaration of the 'jmp_buf' type, commonly provided in the header <setjmp.h>. [-Werror,-Wincomplete-setjmp-declaration]
  dnl extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL;
  dnl            ^
  -Wno-incomplete-setjmp-declaration dnl
  -Wno-gnu-folding-constant dnl Clang specific
])

# Detect warning flags specific to the C compiler and append them to
# WARN_CFLAGS.
m4_define([WARN_FLAGS_C_LIST], [ dnl
  -Wdiscarded-qualifiers dnl
  -Wmissing-prototypes dnl
  -Wmissing-parameter-type dnl
  -Wsuggest-final-types dnl
  -Wsuggest-final-methods dnl
  -Wsuggest-override dnl
])

# Pass -Werror as an extra flag during the test: this is needed to make the
# -Wunknown-warning-option diagnostic fatal with clang.
AC_LANG_PUSH([C])
AX_APPEND_COMPILE_FLAGS([WARN_FLAGS_COMMON_LIST WARN_FLAGS_C_LIST], [WARN_CFLAGS], [-Werror])
AC_LANG_POP([C])

# The test used in AX_APPEND_COMPILE_FLAGS, generated using AC_LANG_PROGRAM, is
# written in such a way that it triggers warnings with the following warning
# flags.  So they would always end up disabled if we put them there, because
# the test program would not build.
#
# Enable them here unconditionally.  They are supported by GCC >= 4.8 and by
# Clang >= 3.3 (required by the project) and are only valid for C code.
WARN_CFLAGS="${WARN_CFLAGS} -Wold-style-definition -Wstrict-prototypes"

# Disable 'strict aliasing' if the C compiler supports it.
AC_LANG_PUSH([C])
AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing], [OPT_CFLAGS], [-Werror])
AC_LANG_POP([C])


##                     ##
## C++ compiler checks ##
##                     ##

# Find a C++11 compiler with GNU extensions (-std=gnu++11)
AX_CXX_COMPILE_STDCXX([11], [ext], [mandatory])

# Detect warning flags specific to the C++ compiler and append them to
# WARN_CXXFLAGS.
m4_define([WARN_FLAGS_CXX_LIST], [ dnl
  dnl GCC enables this with -Wall in C++, and that generates a
  dnl lot of warnings that have on average a low value to fix.
  -Wno-sign-compare dnl
])

# Pass -Werror as an extra flag during the test: this is needed to make the
# -Wunknown-warning-option diagnostic fatal with clang.
AC_LANG_PUSH([C++])
AX_APPEND_COMPILE_FLAGS([WARN_FLAGS_COMMON_LIST WARN_FLAGS_CXX_LIST], [WARN_CXXFLAGS], [-Werror])
AC_LANG_POP([C++])

# Disable 'strict aliasing' if the C++ compiler supports it.
AC_LANG_PUSH([C++])
AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing], [OPT_CXXFLAGS], [-Werror])
AC_LANG_POP([C++])


# When given, add -Werror to WARN_CFLAGS and WARN_CXXFLAGS.
AC_ARG_ENABLE([Werror],[
  AS_HELP_STRING([--enable-Werror], [Treat compiler warnings as errors.])
])

AS_IF([test "x$enable_Werror" = "xyes"], [
  WARN_CFLAGS="${WARN_CFLAGS} -Werror"
  WARN_CXXFLAGS="${WARN_CXXFLAGS} -Werror"
])

# Checks for programs.
AC_PROG_GREP
AC_PROG_MAKE_SET
AC_PROG_SED
AC_PROG_MKDIR_P
AC_PATH_PROG([report_fold], [fold])
LT_INIT

# Check for objcopy, required by the base address statedump and dynamic linker tests
AC_CHECK_TOOL([OBJCOPY], [objcopy])
AS_IF([test "x$OBJCOPY" = "x"],
	[AC_MSG_WARN([Cannot find objcopy. The base address statedump and dynamic linker tests will be disabled. Install the binutils package to remediate this.])]
)
AM_CONDITIONAL([HAVE_OBJCOPY], [test "x$OBJCOPY" != "x"])

# check for pgrep
AC_PATH_PROG([PGREP], [pgrep])
AM_CONDITIONAL([HAVE_PGREP], [test "x$PGREP" != "x"])

AC_PATH_PROG([SHELLCHECK], [shellcheck])
AM_CONDITIONAL([HAVE_SHELLCHECK], [test "x$SHELLCHECK" != "x"])

# set $IN_GIT_REPO if we're in the Git repository; the `bootstrap` file
# is not distributed in tarballs
AS_IF([test -f "$srcdir/bootstrap"], [in_git_repo=yes], [in_git_repo=no])
AM_CONDITIONAL([IN_GIT_REPO], [test "x$in_git_repo" = "xyes"])

# check for bison
AC_PROG_YACC
BISON=$YACC
AX_PROG_BISON_VERSION([2.4], [have_bison=yes])

AS_IF([test "x$have_bison" != "xyes"], [
  AS_IF([test "x$in_git_repo" = "xyes"], [
    AC_MSG_FAILURE([
Bison >= 2.4 is required when building from the Git repository. You can
set the YACC variable to override automatic detection.
    ])
  ], [
    AC_MSG_WARN([
Missing Bison >= 2.4. Note that the parser files are already built in
this distribution tarball, so Bison is only needed if you intend to
modify their sources. You can set the YACC variable to override automatic
detection.
    ])
  ])
])
AM_CONDITIONAL([HAVE_BISON], [test "x$have_bison" = "xyes"])

# check for flex
# Prior to autoconf 2.70, AC_PROG_FLEX did not take an argument. This is not a
# problem since the argument is silently ignored by older versions.
AC_PROG_LEX([noyywrap])
FLEX=$LEX
AX_PROG_FLEX_VERSION([2.5.35], [have_flex=yes])

AS_IF([test "x$have_flex" != "xyes"], [
  AS_IF([test "x$in_git_repo" = "xyes"], [
    AC_MSG_FAILURE([
Flex >= 2.5.35 is required when building from the Git repository. You can
set the LEX variable to override automatic detection.
    ])
  ], [
    AC_MSG_WARN([
Missing Flex >= 2.5.35. Note that the lexer files are already built in
this distribution tarball, so Flex is only needed if you intend to
modify their sources. You can set the LEX variable to override automatic
detection.
    ])
  ])
])
AM_CONDITIONAL([HAVE_FLEX], [test "x$have_flex" = "xyes"])



# Check if linker has the -no-pie option.
AX_CHECK_LINK_FLAG([-no-pie], [linker_have_no_pie_option=yes])
AM_CONDITIONAL([LINKER_HAVE_NO_PIE_OPTION], [test "x$linker_have_no_pie_option" = "xyes"])

AX_LIB_SOCKET_NSL

LT_NO_UNDEFINED=""
AS_CASE([$host_os],
  [cygwin*],
    [
      LT_NO_UNDEFINED="-no-undefined"
    ],
  [cygwin*|darwin*|mingw*|solaris*],
    [
      # On platforms where we only support the relayd, disable the other binaries by default
      AS_IF([test "x$enable_bin_lttng" = "x" ], [enable_bin_lttng=no])
      AS_IF([test "x$enable_bin_lttng_consumerd" = "x" ], [enable_bin_lttng_consumerd=no])
      AS_IF([test "x$enable_bin_lttng_crash" = "x" ], [enable_bin_lttng_crash=no])
      AS_IF([test "x$enable_bin_lttng_sessiond" = "x" ], [enable_bin_lttng_sessiond=no])
      AS_IF([test "x$enable_extras" = "x" ], [enable_extras=no])
      AS_IF([test "x$with_lttng_ust" = "x" ], [with_lttng_ust=no])
    ]
)

AC_SUBST(LT_NO_UNDEFINED)

# Compute minor/major/patchlevel version numbers
major_version=$(echo AC_PACKAGE_VERSION | $SED 's/^\([[0-9]]\)*\.[[0-9]]*\.[[0-9]]*.*$/\1/')
minor_version=$(echo AC_PACKAGE_VERSION | $SED 's/^[[0-9]]*\.\([[0-9]]*\)\.[[0-9]]*.*$/\1/')
patchlevel_version=$(echo AC_PACKAGE_VERSION | $SED 's/^[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\).*$/\1/')

AC_SUBST([MAJOR_VERSION], [$major_version])
AC_SUBST([MINOR_VERSION], [$minor_version])
AC_SUBST([PATCHLEVEL_VERSION], [$patchlevel_version])
AC_DEFINE_UNQUOTED([VERSION_MAJOR], $major_version, [LTTng-Tools major version number])
AC_DEFINE_UNQUOTED([VERSION_MINOR], $minor_version, [LTTng-Tools minor version number])
AC_DEFINE_UNQUOTED([VERSION_PATCHLEVEL], $patchlevel_version, [LTTng-Tools patchlevel version number])

version_name="O-Beer"
version_description="An alcoholic drink made from yeast-fermented malt flavored with hops."
version_description_c=$(echo $version_description | $SED 's/"/\\"/g')

AC_DEFINE_UNQUOTED([VERSION_NAME], ["$version_name"], "")
AC_DEFINE_UNQUOTED([VERSION_DESCRIPTION], ["$version_description_c"], "")

# libtool link_all_deplibs fixup. See http://bugs.lttng.org/issues/321.
AC_ARG_ENABLE(libtool-linkdep-fixup,
	AS_HELP_STRING([--disable-libtool-linkdep-fixup],
			[disable the libtool fixup for linking all dependent libraries (link_all_deplibs)]),
	libtool_fixup=$enableval,
	libtool_fixup=yes)

AS_IF([test "x$libtool_fixup" = "xyes"],
	    [
	    libtool_m4="$srcdir/m4/libtool.m4"
	    libtool_flag_pattern=".*link_all_deplibs\s*,\s*\$1\s*)"
	    AC_MSG_CHECKING([for occurrence(s) of link_all_deplibs = no in $libtool_m4])
	    libtool_flag_pattern_count=$($GREP -c "$libtool_flag_pattern\s*=\s*no" $libtool_m4)
	    AS_IF([test $libtool_flag_pattern_count -ne 0],
	    [
		  AC_MSG_RESULT([$libtool_flag_pattern_count])
		  AC_MSG_WARN([the detected libtool will not link all dependencies, forcing link_all_deplibs = unknown])
		  $SED -i "s/\($libtool_flag_pattern\)\s*=\s*no/\1=unknown/g" $libtool_m4
		  ],
		  [
		  AC_MSG_RESULT([none])
		  ])
	    ])

AM_CONDITIONAL([NO_SHARED], [test x$enable_shared = xno])

AC_CHECK_HEADERS([ \
	sys/types.h unistd.h fcntl.h string.h pthread.h limits.h \
	signal.h stdlib.h sys/un.h sys/socket.h stdlib.h stdio.h \
	getopt.h sys/ipc.h sys/shm.h popt.h grp.h arpa/inet.h \
	netdb.h netinet/in.h paths.h stddef.h sys/file.h sys/ioctl.h \
	sys/mount.h sys/param.h sys/time.h elf.h sys/random.h sys/syscall.h
])

AM_CONDITIONAL([HAVE_ELF_H], [test x$ac_cv_header_elf_h = xyes])

# Basic functions check
AC_CHECK_FUNCS([ \
	atexit bzero clock_gettime dup2 fdatasync fls ftruncate \
	gethostbyname gethostname getpagesize localtime_r memchr memrchr memset \
	mkdir munmap putenv realpath rmdir socket strchr strcspn strdup \
	strncasecmp strndup strnlen strpbrk strrchr strstr strtol strtoul \
	strtoull dirfd gethostbyname2 getipnodebyname epoll_create1 \
	sched_getcpu sysconf sync_file_range getrandom posix_fadvise \
	arc4random flock
])

# Check for pthread_setname_np and pthread_getname_np
LTTNG_PTHREAD_SETNAME_NP
LTTNG_PTHREAD_GETNAME_NP

# Check if clock_gettime, timer_create, timer_settime, and timer_delete are available in lib rt, and if so,
# add -lrt to LIBS
AC_CHECK_LIB([rt], [clock_gettime, timer_create, timer_settime, timer_delete])

# Checks for dl.
AC_CHECK_LIB([dl], [dlopen], [
	have_libdl=yes
	libdl_name=dl
	DL_LIBS="-ldl"
], [
	# libdl not found, check for dlopen in libc.
	AC_CHECK_LIB([c], [dlopen], [
		have_libc_dl=yes
		libdl_name=c
		DL_LIBS="-lc"
	], [
		AC_MSG_ERROR([Cannot find dlopen in libdl nor libc. Use [LDFLAGS]=-Ldir to specify their location.])
	])
])
AC_SUBST(DL_LIBS)

# Check if libdl has dlmopen support.
AH_TEMPLATE([HAVE_DLMOPEN], ["Define to 1 if dlmopen is available."])
AC_CHECK_LIB([$libdl_name], [dlmopen], [
	AC_DEFINE([HAVE_DLMOPEN], [1])
	HAVE_DLMOPEN=1
], [
	HAVE_DLMOPEN=0
])
AC_SUBST(HAVE_DLMOPEN)

# Babeltrace viewer check
AC_ARG_WITH([babeltrace-bin],
	AS_HELP_STRING([--with-babeltrace-bin],
	[Location of the babeltrace viewer executable (including the filename)]),
	[BABELTRACE_BIN="$withval"],
	[BABELTRACE_BIN=''])
AC_SUBST([BABELTRACE_BIN])

AC_ARG_WITH([babeltrace2-bin],
	AS_HELP_STRING([--with-babeltrace2-bin],
	[Location of the babeltrace2 viewer executable (including the filename)]),
	[BABELTRACE2_BIN="$withval"],
	[BABELTRACE2_BIN=''])
AC_SUBST([BABELTRACE2_BIN])

AC_ARG_WITH([consumerd32-bin],
	AS_HELP_STRING([--with-consumerd32-bin],
	[Location of the 32-bit consumerd executable (including the filename)]),
	[CONSUMERD32_BIN="$withval"],
	[CONSUMERD32_BIN=''])
AC_SUBST([CONSUMERD32_BIN])

AC_ARG_WITH([consumerd64-bin],
	AS_HELP_STRING([--with-consumerd64-bin],
	[Location of the 64-bit consumerd executable (including the filename)]),
	[CONSUMERD64_BIN="$withval"],
	[CONSUMERD64_BIN=''])
AC_SUBST([CONSUMERD64_BIN])

AC_ARG_WITH([consumerd32-libdir],
	AS_HELP_STRING([--with-consumerd32-libdir],
	[Directory containing the 32-bit consumerd libraries]),
	[CONSUMERD32_LIBDIR="$withval"],
	[CONSUMERD32_LIBDIR=''])
AC_SUBST([CONSUMERD32_LIBDIR])

AC_ARG_WITH([consumerd64-libdir],
	AS_HELP_STRING([--with-consumerd64-libdir],
	[Directory containing the 64-bit consumerd libraries]),
	[CONSUMERD64_LIBDIR="$withval"],
	[CONSUMERD64_LIBDIR=''])
AC_SUBST([CONSUMERD64_LIBDIR])

AC_ARG_WITH([sessiond-bin],
	AS_HELP_STRING([--with-sessiond-bin],
	[Location of the sessiond executable (including the filename)]),
	[SESSIOND_BIN="$withval"],
	[SESSIOND_BIN=''])
AC_SUBST([SESSIOND_BIN])

AC_ARG_WITH([lttng-system-rundir],
	AS_HELP_STRING([--with-lttng-system-rundir],
	[Location of the system directory where the system-wide lttng-sessiond runtime files are kept. The default is "/var/run/lttng".]),
	[LTTNG_SYSTEM_RUNDIR="$withval"],
	[LTTNG_SYSTEM_RUNDIR="/var/run/lttng"])
AC_SUBST([LTTNG_SYSTEM_RUNDIR])

AC_ARG_ENABLE([test-java-agent-jul],
	[AS_HELP_STRING([--enable-test-java-agent-jul],[enable the LTTng UST Java agent JUL tests [default=no]])],
	[test_java_agent_jul=$enableval],
	[test_java_agent_jul=no]
)

AC_ARG_ENABLE([test-java-agent-log4j],
        [AS_HELP_STRING([--enable-test-java-agent-log4j],[enable the LTTng UST Java agent Log4j 1.x tests [default=no]])],
        [test_java_agent_log4j=$enableval],
        [test_java_agent_log4j=no]
)

AC_ARG_ENABLE([test-java-agent-log4j2],
        [AS_HELP_STRING([--enable-test-java-agent-log4j2],[enable the LTTng UST Java agent Log4j 2.x tests [default=no]])],
        [test_java_agent_log4j2=$enableval],
        [test_java_agent_log4j2=no]
)

AC_ARG_ENABLE([test-java-agent-all],
        [AS_HELP_STRING([--enable-test-java-agent-all],[enable all the LTTng UST Java agent tests [default=no]])],
        [test_java_agent_jul=$enableval
         test_java_agent_log4j=$enableval
         test_java_agent_log4j2=$enableval],
        [:]
)

AC_DEFINE_UNQUOTED([CONFIG_CONSUMERD32_BIN], "$CONSUMERD32_BIN", [Location of the 32-bit consumerd executable.])
AC_DEFINE_UNQUOTED([CONFIG_CONSUMERD64_BIN], "$CONSUMERD64_BIN", [Location of the 64-bit consumerd executable])
AC_DEFINE_UNQUOTED([CONFIG_CONSUMERD32_LIBDIR], "$CONSUMERD32_LIBDIR", [Search for consumerd 32-bit libraries in this location.])
AC_DEFINE_UNQUOTED([CONFIG_CONSUMERD64_LIBDIR], "$CONSUMERD64_LIBDIR", [Search for consumerd 64-bit libraries in this location.])
AC_DEFINE_UNQUOTED([CONFIG_BABELTRACE_BIN], "$BABELTRACE_BIN", [Location of the babeltrace viewer executable.])
AC_DEFINE_UNQUOTED([CONFIG_BABELTRACE2_BIN], "$BABELTRACE2_BIN", [Location of the babeltrace2 viewer executable.])
AC_DEFINE_UNQUOTED([CONFIG_SESSIOND_BIN], "$SESSIOND_BIN", [Location of the sessiond executable.])
AC_DEFINE_UNQUOTED([CONFIG_LTTNG_SYSTEM_RUNDIR], ["$LTTNG_SYSTEM_RUNDIR"], [LTTng system runtime directory])

AC_DEFUN([_AC_DEFINE_AND_SUBST], [
	AC_DEFINE_UNQUOTED([CONFIG_$1], [$2], [$1])
	$1="$2"
	AC_SUBST([$1])
])

AC_DEFUN([_AC_DEFINE_QUOTED_AND_SUBST], [
	AC_DEFINE_UNQUOTED([CONFIG_$1], ["$2"], [$1])
	$1="$2"
	AC_SUBST([$1])
])

# Default values
m4_define([_DEFAULT_CHANNEL_SUBBUF_SIZE], [16384])
m4_define([_DEFAULT_CHANNEL_SUBBUF_NUM], [4])
m4_define([_DEFAULT_CHANNEL_SWITCH_TIMER], [0])
m4_define([_DEFAULT_CHANNEL_LIVE_TIMER], [0])
m4_define([_DEFAULT_CHANNEL_READ_TIMER], [200000])
m4_define([_DEFAULT_CHANNEL_MONITOR_TIMER], [1000000])
m4_define([_DEFAULT_CHANNEL_BLOCKING_TIMEOUT], [0])
_AC_DEFINE_AND_SUBST([DEFAULT_AGENT_TCP_PORT_RANGE_BEGIN], [5345])
_AC_DEFINE_AND_SUBST([DEFAULT_AGENT_TCP_PORT_RANGE_END], [5354])
_AC_DEFINE_AND_SUBST([DEFAULT_APP_SOCKET_RW_TIMEOUT], [5])
_AC_DEFINE_AND_SUBST([DEFAULT_CHANNEL_SUBBUF_SIZE], [_DEFAULT_CHANNEL_SUBBUF_SIZE])
_AC_DEFINE_AND_SUBST([DEFAULT_CHANNEL_TRACEFILE_COUNT], [0])
_AC_DEFINE_AND_SUBST([DEFAULT_CHANNEL_TRACEFILE_SIZE], [0])
_AC_DEFINE_AND_SUBST([DEFAULT_KERNEL_CHANNEL_LIVE_TIMER], [_DEFAULT_CHANNEL_LIVE_TIMER])
_AC_DEFINE_AND_SUBST([DEFAULT_KERNEL_CHANNEL_READ_TIMER], [_DEFAULT_CHANNEL_READ_TIMER])
_AC_DEFINE_AND_SUBST([DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM], [_DEFAULT_CHANNEL_SUBBUF_NUM])
_AC_DEFINE_AND_SUBST([DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE], [1048576])
_AC_DEFINE_AND_SUBST([DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER], [_DEFAULT_CHANNEL_SWITCH_TIMER])
_AC_DEFINE_AND_SUBST([DEFAULT_KERNEL_CHANNEL_MONITOR_TIMER], [_DEFAULT_CHANNEL_MONITOR_TIMER])
_AC_DEFINE_AND_SUBST([DEFAULT_KERNEL_CHANNEL_BLOCKING_TIMEOUT], [_DEFAULT_CHANNEL_BLOCKING_TIMEOUT])
_AC_DEFINE_AND_SUBST([DEFAULT_LTTNG_LIVE_TIMER], [1000000])
_AC_DEFINE_AND_SUBST([DEFAULT_METADATA_CACHE_SIZE], [4096])
_AC_DEFINE_AND_SUBST([DEFAULT_METADATA_READ_TIMER], [0])
_AC_DEFINE_AND_SUBST([DEFAULT_METADATA_SUBBUF_NUM], [2])
_AC_DEFINE_AND_SUBST([DEFAULT_METADATA_SUBBUF_SIZE], [4096])
_AC_DEFINE_AND_SUBST([DEFAULT_METADATA_SWITCH_TIMER], [_DEFAULT_CHANNEL_SWITCH_TIMER])
_AC_DEFINE_AND_SUBST([DEFAULT_NETWORK_CONTROL_PORT], [5342])
_AC_DEFINE_AND_SUBST([DEFAULT_NETWORK_DATA_PORT], [5343])
_AC_DEFINE_AND_SUBST([DEFAULT_NETWORK_VIEWER_PORT], [5344])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_PID_CHANNEL_LIVE_TIMER], [_DEFAULT_CHANNEL_LIVE_TIMER])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_PID_CHANNEL_READ_TIMER], [0])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_PID_CHANNEL_BLOCKING_TIMEOUT], [0])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_PID_CHANNEL_SUBBUF_NUM], [_DEFAULT_CHANNEL_SUBBUF_NUM])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_PID_CHANNEL_SUBBUF_SIZE], [_DEFAULT_CHANNEL_SUBBUF_SIZE])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER], [_DEFAULT_CHANNEL_SWITCH_TIMER])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_PID_CHANNEL_MONITOR_TIMER], [_DEFAULT_CHANNEL_MONITOR_TIMER])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_UID_CHANNEL_LIVE_TIMER], [_DEFAULT_CHANNEL_LIVE_TIMER])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_UID_CHANNEL_READ_TIMER], [0])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_UID_CHANNEL_BLOCKING_TIMEOUT], [0])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_UID_CHANNEL_SUBBUF_NUM], [_DEFAULT_CHANNEL_SUBBUF_NUM])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_UID_CHANNEL_SUBBUF_SIZE], [524288])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER], [_DEFAULT_CHANNEL_SWITCH_TIMER])
_AC_DEFINE_AND_SUBST([DEFAULT_UST_UID_CHANNEL_MONITOR_TIMER], [_DEFAULT_CHANNEL_MONITOR_TIMER])
_AC_DEFINE_QUOTED_AND_SUBST([DEFAULT_AGENT_BIND_ADDRESS], [localhost])
_AC_DEFINE_QUOTED_AND_SUBST([DEFAULT_NETWORK_CONTROL_BIND_ADDRESS], [0.0.0.0])
_AC_DEFINE_QUOTED_AND_SUBST([DEFAULT_NETWORK_DATA_BIND_ADDRESS], [0.0.0.0])
_AC_DEFINE_QUOTED_AND_SUBST([DEFAULT_NETWORK_VIEWER_BIND_ADDRESS], [localhost])
_AC_DEFINE_AND_SUBST([DEFAULT_NETWORK_RELAYD_CTRL_MAX_PAYLOAD_SIZE], [134217728])
_AC_DEFINE_AND_SUBST([DEFAULT_ROTATE_PENDING_TIMER], [500000])
_AC_DEFINE_AND_SUBST([DEFAULT_EVENT_NOTIFIER_ERROR_COUNT_MAP_SIZE], [4096])

# Command short descriptions
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_ADD_CONTEXT], [Add context fields to be recorded])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_ADD_TRIGGER], [Add a trigger])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_CLEAR], [Clear a recording session])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_CREATE], [Create a recording session])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_DESTROY], [Destroy recording sessions])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_DISABLE_CHANNEL], [Disable channels])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_DISABLE_EVENT], [Disable recording event rules])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_DISABLE_ROTATION], [Unset a recording session rotation schedule])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_ENABLE_CHANNEL], [Create or enable a channel])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_ENABLE_EVENT], [Create or enable recording event rules])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_ENABLE_ROTATION], [Set a recording session rotation schedule])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_HELP], [Show the help of a command])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_LIST], [List recording sessions and instrumentation points])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_LIST_TRIGGERS], [List triggers])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_LOAD], [Load recording session configurations])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_REGENERATE], [Regenerate specific recording session data])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_REMOVE_TRIGGER], [Remove a trigger])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_ROTATE], [Archive the current trace chunk of a recording session])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_SAVE], [Save recording session configurations])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_SET_SESSION], [Set the current recording session])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_SNAPSHOT], [Take a recording session snapshot])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_START], [Start a recording session])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_STATUS], [Show the status of the current recording session])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_STOP], [Stop a recording session])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_TRACK], [Allow specific processes to record events])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_UNTRACK], [Disallow specific processes to record events])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_VERSION], [Show LTTng-tools version information])
_AC_DEFINE_QUOTED_AND_SUBST([CMD_DESCR_VIEW], [Launch a trace reader])

if test "x$prefix" = "xNONE"; then
	prefix=$ac_default_prefix
fi
CONFDIR=`eval echo $sysconfdir`
AC_SUBST(CONFDIR)
AC_DEFINE_UNQUOTED([CONFIG_LTTNG_SYSTEM_CONFIGDIR],"$CONFDIR", [LTTng system configuration directory.])

AX_DEFINE_DIR([CONFIG_LTTNG_SYSTEM_DATADIR], [datadir], [LTTng system data directory.])

# Check libpopt
PKG_CHECK_MODULES([POPT], [popt],
  [
    dnl PKG_CHECK_MODULES defines POPT_LIBS
  ],
  [
    AC_MSG_WARN([pkg-config was unable to find a valid .pc for libpopt. Set PKG_CONFIG_PATH to specify the pkgconfig configuration file location])
    AC_MSG_WARN([Finding libpopt without pkg-config.])
    AC_CHECK_LIB([popt],
      [poptGetContext],
      [POPT_LIBS="-lpopt"],
      [
        AC_MSG_FAILURE([Cannot find libpopt. Either set PKG_CONFIG_PATH to the configuration file location or use LDFLAGS=-Ldir to specify the library location])
      ]
    )
  ]
)
AC_SUBST(POPT_LIBS)

PKG_CHECK_MODULES([libxml2], [libxml-2.0 >= 2.7.6])

AC_CHECK_FUNC([clock_gettime], [AC_DEFINE_UNQUOTED([LTTNG_HAVE_CLOCK_GETTIME], 1, [Has clock_gettime() support.])])

# URCU library version needed or newer
PKG_CHECK_MODULES([URCU], [liburcu >= 0.14])
PKG_CHECK_MODULES([URCU_CDS], [liburcu-cds >= 0.14])
AM_CPPFLAGS="$AM_CPPFLAGS $URCU_CFLAGS"

# Check for libkmod, it will be auto-neabled if found but won't fail if it's not,
# it can be explicitly disabled with --without-kmod
AH_TEMPLATE([HAVE_KMOD], [Define if you have kmod support])
AC_ARG_WITH([kmod],
  [AS_HELP_STRING([--with-kmod], [build with lkmod support @<:@default=check@:>@])],
  [],
  [with_kmod=check]
)

AS_IF([test "x$with_kmod" != "xno"],
  [
    AC_CHECK_LIB([kmod], [kmod_module_probe_insert_module],
      [
        AC_DEFINE([HAVE_KMOD], [1])
        KMOD_LIBS="-lkmod"
      ],
      [
        if test "x$with_kmod" != xcheck; then
          AC_MSG_FAILURE([Cannot find libkmod. Use [LDFLAGS]=-Ldir and [CPPFLAGS]=-Idir to specify its location.])
        else
          with_kmod=no
        fi
      ]
    )
  ]
)
AC_SUBST(KMOD_LIBS)

# Check for liblttng-ust-ctl, fail if it's not found,
# it can be explicitly disabled with --without-lttng-ust
AH_TEMPLATE([HAVE_LIBLTTNG_UST_CTL], [Define if you have LTTng-UST control support])
AC_ARG_WITH([lttng-ust],
  [AS_HELP_STRING([--without-lttng-ust], [build without LTTng-UST (Userspace Tracing) support])],
  [],
  [with_lttng_ust=yes]
)

AS_IF([test "x$with_lttng_ust" = "xyes"], [
  AC_DEFINE([HAVE_LIBLTTNG_UST_CTL], [1])

  # Check for liblttng-ust
  PKG_CHECK_MODULES([UST], [lttng-ust >= $major_version.$minor_version])

  # Check for liblttng-ust-ctl
  PKG_CHECK_MODULES([UST_CTL], [lttng-ust-ctl >= $major_version.$minor_version])

  AM_CPPFLAGS="$AM_CPPFLAGS $UST_CFLAGS"
])

AM_CONDITIONAL([HAVE_LIBLTTNG_UST_CTL], [test "x$with_lttng_ust" = "xyes"])


# Check for fmemopen
AC_CHECK_LIB([c], [fmemopen],
[
	AC_DEFINE_UNQUOTED([LTTNG_HAVE_FMEMOPEN], 1, [Has fmemopen support.])
]
)

# check for libpfm
AC_CHECK_LIB([pfm], [pfm_initialize],
	     [
	      have_libpfm=yes
	      ])
AM_CONDITIONAL([LTTNG_TOOLS_BUILD_WITH_LIBPFM], [test "x$have_libpfm" = "xyes"])

# For Python
# SWIG version needed or newer:
swig_version=2.0.0

AC_ARG_ENABLE([python-bindings],
              [AS_HELP_STRING([--enable-python-bindings],
                              [compile Python bindings])],
              [enable_python_binding=$enableval], [enable_python_binding=no])

AM_CONDITIONAL([PYTHON_BINDING], [test "x$enable_python_binding" = xyes])

if test "x$enable_python_binding" = xyes; then
  AX_PKG_SWIG($swig_version, [], [ AC_MSG_ERROR([SWIG $swig_version or newer is needed]) ])
  AS_IF([test x$enable_shared = xno], [ AC_MSG_ERROR([Python bindings require shared libraries.]) ])
  AM_PATH_PYTHON([3.4])

  AC_ARG_VAR([PYTHON_INCLUDE], [Include flags for python, bypassing python-config])
  AC_ARG_VAR([PYTHON_CONFIG], [Path to python-config])
  AS_IF([test -z "$PYTHON_INCLUDE"], [
    AS_IF([test -z "$PYTHON_CONFIG"], [
      AC_PATH_PROGS([PYTHON_CONFIG],
                    [python$PYTHON_VERSION-config python-config],
                    [],
                    [`dirname $PYTHON`])
      AS_IF([test "x$PYTHON_CONFIG" = "x"], [AC_MSG_ERROR([cannot find python-config for $PYTHON. Do you have python-dev installed?])])
    ])
    AC_MSG_CHECKING([python include flags])
    PYTHON_INCLUDE=`$PYTHON_CONFIG --includes`
    AC_MSG_RESULT([$PYTHON_INCLUDE])
  ])

else
    AC_MSG_NOTICE([You may configure with --enable-python-bindings ]dnl
[if you want Python bindings.])

fi

# Epoll check. If not present, the build will fallback on poll() API
AX_HAVE_EPOLL(
	[AX_CONFIG_FEATURE_ENABLE(epoll)],
	[AX_CONFIG_FEATURE_DISABLE(epoll)]
)
AX_CONFIG_FEATURE(
	[epoll], [This platform supports epoll(7)],
	[HAVE_EPOLL], [This platform supports epoll(7).]
)

AS_IF([test "x$ac_cv_func_dirfd" = "xyes"],
	[AX_CONFIG_FEATURE_ENABLE(dirfd)],
	[AX_CONFIG_FEATURE_DISABLE(dirfd)]
)
AX_CONFIG_FEATURE(
	[dirfd], [Use directory file descriptors],
	[HAVE_DIRFD], [This platform supports directory file descriptors.]
)

AM_CONDITIONAL([TEST_JAVA_JUL_AGENT], [test "x$test_java_agent_jul" = "xyes"])
AM_CONDITIONAL([TEST_JAVA_LOG4J_AGENT], [test "x$test_java_agent_log4j" = "xyes"])
AM_CONDITIONAL([TEST_JAVA_LOG4J2_AGENT], [test "x$test_java_agent_log4j2" = "xyes"])

if test "x$test_java_agent_jul" = "xyes" || test "x$test_java_agent_log4j" = "xyes" || test "x$test_java_agent_log4j2" = "xyes"; then
	AX_JAVA_OPTIONS
	AX_PROG_JAVAC
	AX_PROG_JAVA
	AX_PROG_JAR

	AX_CHECK_CLASSPATH

	# Check for Java UST agent common class first
	AX_CHECK_CLASS(org.lttng.ust.agent.AbstractLttngAgent)
	if test "x$ac_cv_class_org_lttng_ust_agent_AbstractLttngAgent" = "xno"; then
		AC_MSG_ERROR([The UST Java agent common class was not found. Please specify the location of the jar via the Java CLASSPATH e.g: export CLASSPATH="/path/to/lttng-ust-agent-common.jar"])
	fi

	if test "x$test_java_agent_jul" = "xyes"; then
		# Check for JUL agent class
		AX_CHECK_CLASS(org.lttng.ust.agent.jul.LttngLogHandler)
		if test "x$ac_cv_class_org_lttng_ust_agent_jul_LttngLogHandler" = "xno"; then
			AC_MSG_ERROR([The UST Java agent JUL class was not found. Please specify the location of the jar via the Java CLASSPATH e.g: export CLASSPATH="/path/to/lttng-ust-agent-jul.jar"])
		fi
	fi

	if test "x$test_java_agent_log4j" = "xyes"; then
		# Check for Log4j agent class
		AX_CHECK_CLASS(org.lttng.ust.agent.log4j.LttngLogAppender)
		if test "x$ac_cv_class_org_lttng_ust_agent_log4j_LttngLogAppender" = "xno"; then
			AC_MSG_ERROR([The UST Java agent Log4j class was not found. Please specify the location of the jar via the Java CLASSPATH e.g: export CLASSPATH="/path/to/lttng-ust-agent-log4j.jar"])
		fi

		# Check for Log4j class
		AX_CHECK_CLASS(org.apache.log4j.Logger)
		if test "x$ac_cv_class_org_apache_log4j_Logger" = "xno"; then
			AC_MSG_ERROR([The Log4j class was not found. Please specify the location of the jar via the Java CLASSPATH e.g: export CLASSPATH="/path/to/log4j.jar"])
		fi
	fi

	if test "x$test_java_agent_log4j2" = "xyes"; then
		# Check for Log4j2 agent class
		AX_CHECK_CLASS(org.lttng.ust.agent.log4j2.LttngLogAppender)
		if test "x$ac_cv_class_org_lttng_ust_agent_log4j2_LttngLogAppender" = "xno"; then
			AC_MSG_ERROR([The UST Java agent Log4j 2.x class was not found. Please specify the location of the jar via the Java CLASSPATH e.g: export CLASSPATH="/path/to/lttng-ust-agent-log4j2.jar"])
		fi

		# Check for Log4j 2.x classes
		AX_CHECK_CLASS([org.apache.logging.log4j.Logger])
		AX_CHECK_CLASS([org.apache.logging.log4j.core.Core])
		if test "x$ac_cv_class_org_apache_logging_log4j_Logger" = "xno" || test "x$ac_cv_class_org_apache_logging_log4j_core_Core" = "xno"; then
			AC_MSG_ERROR([The Log4j 2.x API or core class was not found. Please specify the location of the jars via the Java CLASSPATH e.g: export CLASSPATH="/path/to/log4j-core.jar:/path/to/log4j-api.jar"])
		fi
	fi
fi

# API documentation using Doxygen
AC_ARG_ENABLE([api-doc], [
	AS_HELP_STRING([--enable-api-doc], [build HTML API documentation])
], [api_doc=$enableval], [api_doc=no])

AS_IF([test "x$api_doc" = xyes], [
	DX_DOXYGEN_FEATURE(ON)
	DX_DOT_FEATURE(OFF)
	DX_HTML_FEATURE(ON)
	DX_CHM_FEATURE(OFF)
	DX_CHI_FEATURE(OFF)
	DX_MAN_FEATURE(OFF)
	DX_RTF_FEATURE(OFF)
	DX_XML_FEATURE(OFF)
	DX_PDF_FEATURE(OFF)
	DX_PS_FEATURE(OFF)
	DX_INIT_DOXYGEN(["LTTng control library"], [$(builddir)/Doxyfile], [output])

	AS_IF([test -z "$DX_DOXYGEN"], [
		AC_MSG_ERROR([You need Doxygen to build the liblttng-ctl API documentation])
	])
])

AM_CONDITIONAL([API_DOC], [test "x$api_doc" = xyes])

# enable building man pages (user's intention)
AC_ARG_ENABLE(
	man-pages,
	AS_HELP_STRING(
		[--disable-man-pages],
		[Do not build and install man pages (already built in a distributed tarball)]
	),
	[man_pages_opt=$enableval],
	[man_pages_opt=yes]
)

# check for asciidoc and xmlto if we enabled building the man pages
have_asciidoc_xmlto=no
warn_prebuilt_man_pages=no

AS_IF([test "x$man_pages_opt" = "xyes"], [
	AC_PATH_PROG([ASCIIDOC], [asciidoc])
	AC_PATH_PROG([XMLTO], [xmlto])

	AS_IF([test "x$ASCIIDOC" = "x" || test "x$XMLTO" = "x"], [
		AS_IF([test "x$in_git_repo" = "xyes"], [
			# this is an error because we're in the Git repo, which
			# means the man pages are not already generated for us,
			# thus asciidoc/xmlto are required because we were asked
			# to build the man pages
			AC_MSG_ERROR([
You need asciidoc and xmlto to build the LTTng-tools man pages. Use
--disable-man-pages to disable building the man pages, in which case
they will not be installed.
			])
		], [
			# only warn here: since we're in the tarball, the man
			# pages should already be generated at this point, thus
			# asciidoc/xmlto are not strictly required
			warn_prebuilt_man_pages=yes
		])
	], [
		have_asciidoc_xmlto=yes
	])
])

# export man page build condition: build the man pages if the user
# asked for it, and if the tools are available
AM_CONDITIONAL([MAN_PAGES_OPT], [test "x$man_pages_opt" != "xno"])
AM_CONDITIONAL([HAVE_ASCIIDOC_XMLTO], [test "x$have_asciidoc_xmlto" = "xyes"])

AC_DEFINE_UNQUOTED([MANPATH], ["`eval eval echo $mandir`"], [Path to man pages.])

# embedded --help message
AC_ARG_ENABLE(
	[embedded-help],
	AS_HELP_STRING(
		[--enable-embedded-help],
		[Embed the --help messages in the executable files]
	),
	[embedded_help=$enableval],
	[embedded_help=no]
)
AS_IF([test "x$embedded_help" = "xyes"], [
	AS_IF([test "x$man_pages_opt" = "xno"], [
		AC_MSG_ERROR([You need the --enable-man-pages option with the --enable-embedded-help option.])
	])
	AC_PATH_PROG([man_prog_path], [man])
	AS_IF([test "x$man_prog_path" = "x"], [
		AC_MSG_ERROR([You need man with the --enable-embedded-help option.])
	])
	AC_DEFINE_UNQUOTED([LTTNG_EMBED_HELP], 1, [Embed --help messages.])
	AC_SUBST([MANPROG], [$man_prog_path])
])
AM_CONDITIONAL([EMBED_HELP], [test "x$embedded_help" != "xno"])

# Python agent test
UST_PYTHON_AGENT="lttngust"

AC_ARG_ENABLE(test-python2-agent,
	AS_HELP_STRING([--enable-test-python2-agent],
		[enable tests for python2 agent. Python2 interpreter path can be overridden by setting the PYTHON2 environment variable. Default: Autodetect]
	),[:],[test_python2_agent_autodetect=yes]
)

AC_ARG_ENABLE(test-python3-agent,
	AS_HELP_STRING([--enable-test-python3-agent],
		[enable tests for python3 agent. Python3 interpreter path can be overridden by setting the PYTHON3 environment variable. Default: Autodetect]
	),[:],[test_python3_agent_autodetect=yes]
)

AC_ARG_ENABLE(test-python-agent-all,
	AS_HELP_STRING([--enable-test-python-agent-all],
		[enable test for all python{2/3} agent.]
	),
)

AS_IF([test ! -z "$enable_test_python_agent_all"], [
       unset test_python2_agent_autodetect
       unset test_python3_agent_autodetect
])

AS_IF([test "x$enable_test_python_agent_all" = "xyes"], [
       enable_test_python2_agent=yes
       enable_test_python3_agent=yes
])

AS_IF([test "x$enable_test_python_agent_all" = "xno"], [
       enable_test_python2_agent=no
       enable_test_python3_agent=no
])


AS_IF([test "x$enable_test_python2_agent" = "xyes" -o "x$test_python2_agent_autodetect" = "xyes" ], [
	AS_IF([test -z "$PYTHON2"], [
			PYTHON2=python2
		], [
			AC_MSG_WARN([Using user-defined PYTHON2 ($PYTHON2) for lttng-ust python2 agent check])
	])

	AC_PATH_PROG([PYTHON2_BIN],[$PYTHON2])
	AS_IF([test -z "$PYTHON2_BIN"], [
		AS_IF([test -z "$test_python2_agent_autodetect"],[
			AC_MSG_ERROR([No python2 interpreter found. PYTHON2 can be set to override default interpreter path])
		])
	], [
		AC_MSG_CHECKING([for python2 lttng-ust agent])
		AS_IF([$PYTHON2_BIN -c "import $UST_PYTHON_AGENT" 2>/dev/null], [
			PYTHON2_AGENT=$PYTHON2_BIN
			AC_MSG_RESULT([yes])
			RUN_PYTHON_AGENT_TEST=yes
		], [
			AC_MSG_RESULT([no])
			AS_IF([test -z "$test_python2_agent_autodetect"],[
				AC_MSG_ERROR([No python2 agent found. The path to the agent can be specified by setting the PYTHONPATH environment variable.])
			])
		])

	])

])

AS_IF([test "x$enable_test_python3_agent" = "xyes" -o "x$test_python3_agent_autodetect" = "xyes" ], [
	AS_IF([test -z "$PYTHON3"], [
		PYTHON3=python3
	], [
		AC_MSG_WARN([Using user-defined PYTHON3 ($PYTHON3) for lttng-ust python3 agent check])
	])

	AC_PATH_PROG([PYTHON3_BIN],[$PYTHON3])
	AS_IF([test -z "$PYTHON3_BIN"], [
		AS_IF([test -z "$test_python3_agent_autodetect"],[
			AC_MSG_ERROR([No python3 interpreter found. PYTHON3 can be set to override default interpreter path])
		])
	], [
		AC_MSG_CHECKING([for python3 lttng-ust agent])
		AS_IF([$PYTHON3_BIN -c "import $UST_PYTHON_AGENT" 2>/dev/null], [
			PYTHON3_AGENT=$PYTHON3_BIN
			AC_MSG_RESULT([yes])
			RUN_PYTHON_AGENT_TEST=yes
		], [
			AC_MSG_RESULT([no])
			AS_IF([test -z "$test_python3_agent_autodetect"],[
				AC_MSG_ERROR([No python3 agent found. The path to the agent can be specified by setting the PYTHONPATH environment variable.])
			])
		])

	])
])
AC_SUBST([RUN_PYTHON_AGENT_TEST])
AC_SUBST([PYTHON2_AGENT])
AC_SUBST([PYTHON3_AGENT])

AC_ARG_ENABLE([test-sdt-uprobe],
  [AS_HELP_STRING([--enable-test-sdt-uprobe], [enable the LTTng UST SDT uprobe tests [default=autodetect]])],
  [test_sdt_uprobe="$enableval"],
  [test_sdt_uprobe=autodetect]
)

AS_IF([test "$test_sdt_uprobe" != "no"], [
  LTTNG_CHECK_SDT_WORKS
  AC_PATH_PROG([DTRACE], [dtrace])
])

AS_IF([test "$test_sdt_uprobe" = "yes"], [
  AS_IF([test "$lttng_cv_sdt_works" = "no"], [
    AC_MSG_ERROR([Cannot find 'sys/sdt.h'.])
  ])
  AS_IF([test "x$DTRACE" = "x"], [
    AC_MSG_ERROR([Cannot find SystemTap dtrace. You can set the DTRACE variable to override automatic detection.])
  ])
])

AS_IF([test "$test_sdt_uprobe" = "autodetect"], [
  AS_IF([test "$lttng_cv_sdt_works" = "yes"], [
    AS_IF([test "x$DTRACE" != "x"], [
      test_sdt_uprobe=yes
    ])
  ])
])

AM_CONDITIONAL([TEST_SDT_UPROBE], [test "$test_sdt_uprobe" = "yes"])

AC_ARG_ENABLE(
	[precious-tests],
	AS_HELP_STRING(
		[--disable-precious-tests],
		[Delete log files for interrupted tests]
	),
	[precious_tests=$enableval],
	[precious_tests=yes]
)

AM_CONDITIONAL([PRECIOUS_TESTS], [test x$precious_tests = xyes])

AC_ARG_ENABLE([lib-lttng-ctl], AS_HELP_STRING([--disable-lib-lttng-ctl],
	[Disable the build of liblttng-ctl (only possible if no binaries that depend on it are built)]))

# Arguments for binaries build exclusion
AC_ARG_ENABLE([bin-lttng], AS_HELP_STRING([--disable-bin-lttng],[Disable the build of lttng binaries]))
AC_ARG_ENABLE([bin-lttng-consumerd], AS_HELP_STRING([--disable-bin-lttng-consumerd],
	      [Disable the build of lttng-consumerd binaries]))
AC_ARG_ENABLE([bin-lttng-crash], AS_HELP_STRING([--disable-bin-lttng-crash],[Disable the build of lttng-crash binaries]))
AC_ARG_ENABLE([bin-lttng-relayd], AS_HELP_STRING([--disable-bin-lttng-relayd],
	      [Disable the build of lttng-relayd binaries]))
AC_ARG_ENABLE([bin-lttng-sessiond], AS_HELP_STRING([--disable-bin-lttng-sessiond],
	      [Disable the build of lttng-sessiond binaries]))
AC_ARG_ENABLE([extras], AS_HELP_STRING([--disable-extras],
	      [Disable the build of the extra components]))


build_lib_consumer=no
build_lib_health=no
build_lib_index=no
build_lib_kernel_consumer=no
build_lib_kernel_ctl=no
build_lib_lttng_ctl=no
build_lib_relayd=no
build_lib_sessiond_comm=no
build_lib_testpoint=no
build_lib_ust_consumer=no

# There is an overlap for enabled dependencies, but this makes everything
# simpler. libcommon and libconfig are always compiled so they are not repeated
# here.

# Enable binary dependencies.
AS_IF([test x$enable_bin_lttng != xno],
      [
       build_lib_lttng_ctl=yes
      ]
)

AS_IF([test x$enable_bin_lttng_consumerd != xno],
      [
       build_lib_consumer=yes
       build_lib_sessiond_comm=yes
       build_lib_index=yes
       build_lib_health=yes
       build_lib_testpoint=yes
      ]
)

AS_IF([test x$enable_bin_lttng_crash != xno],
      # Do nothing since libconfig and libcommon are built by default.
      []
)

AS_IF([test x$enable_bin_lttng_relayd != xno],
      [
       build_lib_sessiond_comm=yes
       build_lib_index=yes
       build_lib_health=yes
       build_lib_testpoint=yes
      ]
)
AS_IF([test x$enable_bin_lttng_sessiond != xno],
      [
       build_lib_lttng_ctl=yes
       build_lib_sessiond_comm=yes
       build_lib_kernel_ctl=yes
       build_lib_relayd=yes
       build_lib_testpoint=yes
       build_lib_health=yes
      ]
)

# Libraries dependencies enabling
# If we want to build liblttng-ctl
AS_IF([test x$enable_lib_lttng_ctl != xno],
      [
       build_lib_lttng_ctl=yes
      ]
)
# If we need to build liblttng-ctl because a binary depends on it
AS_IF([test x$build_lib_lttng_ctl = xyes],
      [
       build_lib_sessiond_comm=yes
      ]
)
# Fail if we didn't want to build liblttng-ctl but need to build it anyway
AS_IF([test "x$build_lib_lttng_ctl" = "xyes" -a "x$enable_lib_lttng_ctl" = "xno"],[
	AC_MSG_FAILURE(
		[liblttng-ctl must be built, because at least one binary that depends on it is enabled])
])

AS_IF([test x$build_lib_consumer = xyes],
      [
       build_lib_sessiond_comm=yes
       build_lib_kernel_consumer=yes
       build_lib_relayd=yes
       AS_IF([test "x$with_lttng_ust" = "xyes"], [build_lib_ust_consumer=yes])
      ]
)

AS_IF([test x$build_lib_kernel_consumer = xyes],
      [
       build_lib_kernel_ctl=yes
       build_lib_relayd=yes
      ]
)

AS_IF([test x$build_lib_relayd = xyes],
      [
       build_lib_sessiond_comm=yes
      ]
)

# Find arch type
AS_CASE([$host_cpu],
        [k1om], [ARCHTYPE="x86"],
        [i386], [ARCHTYPE="x86"],
        [i486], [ARCHTYPE="x86"],
        [i586], [ARCHTYPE="x86"],
        [i686], [ARCHTYPE="x86"],
        [amd64], [ARCHTYPE="x86"],
        [x86_64], [ARCHTYPE="x86"],
        [powerpc], [ARCHTYPE="ppc"],
        [ppc64], [ARCHTYPE="ppc"],
        [powerpc64], [ARCHTYPE="ppc"],
        [powerpc64le], [ARCHTYPE="ppc"],
        [ppc], [ARCHTYPE="ppc"],
        [s390], [ARCHTYPE="s390"],
        [s390x], [ARCHTYPE="s390"],
        [sparc], [ARCHTYPE="sparc64"],
        [sparc64], [ARCHTYPE="sparc64"],
        [alpha*], [ARCHTYPE="alpha"],
        [ia64], [ARCHTYPE="ia64"],
        [arm*], [ARCHTYPE="arm"],
        [aarch64*], [ARCHTYPE="aarch64"],
        [mips*], [ARCHTYPE="mips"],
        [nios2*], [ARCHTYPE="nios2"],
        [tile*], [ARCHTYPE="tile"],
        [hppa*], [ARCHTYPE="hppa"],
        [m68k], [ARCHTYPE="m68k"],
        [riscv*], [ARCHTYPE="riscv"],
        [ARCHTYPE="unknown"]
)

AC_SUBST(ARCHTYPE)

AS_CASE([$host_os],
	[linux*], [OSTYPE="linux"],
	[freebsd*], [OSTYPE="freebsd"],
	[solaris*], [OSTYPE="solaris"],
	[cygwin*], [OSTYPE="cygwin"],
	[mingw*], [OSTYPE="mingw"],
	[OSTYPE="unknown"]
)
AC_SUBST(OSTYPE)
AM_CONDITIONAL([IS_LINUX], [test $OSTYPE = "linux"])



# Userspace callstack capture is only supported by the Linux kernel on x86.
AH_TEMPLATE([HAVE_MODULES_USERSPACE_CALLSTACK_CONTEXT], [Define if you have LTTng-modules userspace callstack tracing support])
AS_IF([test "x$ARCHTYPE" = "xx86" && test "x$OSTYPE" = "xlinux"],[
        have_modules_userspace_callstack_context=yes
        AC_DEFINE([HAVE_MODULES_USERSPACE_CALLSTACK_CONTEXT], [1])
])
AM_CONDITIONAL([HAVE_MODULES_USERSPACE_CALLSTACK_CONTEXT], [test x$have_modules_userspace_callstack_context = xyes])

# Export binaries build conditions.
AM_CONDITIONAL([BUILD_BIN_LTTNG], [test x$enable_bin_lttng != xno])
AM_CONDITIONAL([BUILD_BIN_LTTNG_CONSUMERD], [test x$enable_bin_lttng_consumerd != xno])
AM_CONDITIONAL([BUILD_BIN_LTTNG_CRASH], [test x$enable_bin_lttng_crash != xno])
AM_CONDITIONAL([BUILD_BIN_LTTNG_RELAYD], [test x$enable_bin_lttng_relayd != xno])
AM_CONDITIONAL([BUILD_BIN_LTTNG_SESSIOND], [test x$enable_bin_lttng_sessiond != xno])

# Export the tests and extras build conditions.
AS_IF([\
test "x$enable_bin_lttng" != "xno" && \
test "x$enable_bin_lttng_consumerd" != "xno" && \
test "x$enable_bin_lttng_crash" != "xno" && \
test "x$enable_bin_lttng_relayd" != "xno" && \
test "x$enable_bin_lttng_sessiond" != "xno"],
[build_tests=yes],
[build_tests=no]
)

AM_CONDITIONAL([BUILD_TESTS], [test x$build_tests = xyes])

AS_IF([test "x$build_tests" = "xyes"],
  [
    PKG_CHECK_MODULES([babeltrace2], [babeltrace2])
  ]
)

AM_CONDITIONAL([BUILD_EXTRAS], [test x$enable_extras != xno])

# Export libraries build conditions.
AM_CONDITIONAL([BUILD_LIB_CONSUMER], [test x$build_lib_consumer = xyes])
AM_CONDITIONAL([BUILD_LIB_HEALTH], [test x$build_lib_health = xyes])
AM_CONDITIONAL([BUILD_LIB_INDEX], [test x$build_lib_index = xyes])
AM_CONDITIONAL([BUILD_LIB_KERNEL_CONSUMER], [test x$build_lib_kernel_consumer = xyes])
AM_CONDITIONAL([BUILD_LIB_KERNEL_CTL], [test x$build_lib_kernel_ctl = xyes])
AM_CONDITIONAL([BUILD_LIB_LTTNG_CTL], [test x$build_lib_lttng_ctl = xyes])
AM_CONDITIONAL([BUILD_LIB_RELAYD], [test x$build_lib_relayd = xyes])
AM_CONDITIONAL([BUILD_LIB_SESSIOND_COMM], [test x$build_lib_sessiond_comm = xyes])
AM_CONDITIONAL([BUILD_LIB_TESTPOINT], [test x$build_lib_testpoint = xyes])
AM_CONDITIONAL([BUILD_LIB_UST_CONSUMER], [test x$build_lib_ust_consumer = xyes])

AM_CFLAGS="-fvisibility=hidden $OPT_CFLAGS $WARN_CFLAGS $PTHREAD_CFLAGS"
AC_SUBST(AM_CFLAGS)

AM_CXXFLAGS="-fvisibility=hidden -fvisibility-inlines-hidden $OPT_CXXFLAGS $WARN_CXXFLAGS $PTHREAD_CFLAGS"
AC_SUBST(AM_CXXFLAGS)

# This is set even though it is empty, so Makefiles can do "AM_LDFLAGS += ...".
AM_LDFLAGS=""
AC_SUBST(AM_LDFLAGS)

# The order in which the include folders are searched is important.
# The top_builddir should always be searched first in the event that a build
# time generated file is included. An example of this is the "version.i" file.
# In a scenario where lttng-tools is built from a distribution tarball and in a
# out-of-tree manner, the generated "version.i" has priority on the one from
# the source (distribution tarball) and must be found first.
AM_CPPFLAGS="-I\$(top_builddir)/include -I\$(top_srcdir)/include -I\$(top_builddir)/src -I\$(top_srcdir)/src -include config.h $AM_CPPFLAGS"
AC_SUBST(AM_CPPFLAGS)

lttngincludedir="${includedir}/lttng"
AC_SUBST(lttngincludedir)

lttngactionincludedir="${includedir}/lttng/action"
AC_SUBST(lttngactionincludedir)

lttngconditionincludedir="${includedir}/lttng/condition"
AC_SUBST(lttngconditionincludedir)

lttngnotificationincludedir="${includedir}/lttng/notification"
AC_SUBST(lttngnotificationincludedir)

lttngtriggerincludedir="${includedir}/lttng/trigger"
AC_SUBST(lttngtriggerincludedir)

lttngeventruleincludedir="${includedir}/lttng/event-rule"
AC_SUBST(lttngeventruleincludedir)

lttnglibexecdir="${libdir}/lttng/libexec"
AC_SUBST(lttnglibexecdir)

AC_CONFIG_FILES([
	Makefile
	doc/Makefile
	doc/api/Makefile
	doc/api/liblttng-ctl/Doxyfile
	doc/api/liblttng-ctl/Makefile
	doc/examples/Makefile
	doc/examples/rotation/Makefile
	doc/examples/trigger-condition-event-matches/Makefile
	doc/man/Makefile
	doc/man/asciidoc-attrs.conf
	include/Makefile
	extras/Makefile
	extras/bindings/Makefile
	extras/bindings/swig/Makefile
	extras/bindings/swig/python/Makefile
	extras/core-handler/Makefile
	src/Makefile
	src/common/Makefile
	src/lib/Makefile
	src/lib/lttng-ctl/Makefile
	src/lib/lttng-ctl/lttng-ctl.pc
	src/bin/Makefile
	src/bin/lttng-consumerd/Makefile
	src/bin/lttng-sessiond/Makefile
	src/bin/lttng-relayd/Makefile
	src/bin/lttng/Makefile
	src/bin/lttng-crash/Makefile
	src/vendor/Makefile
	src/vendor/msgpack/Makefile
	tests/Makefile
	tests/destructive/Makefile
	tests/meta/Makefile
	tests/regression/Makefile
	tests/regression/kernel/Makefile
	tests/regression/tools/Makefile
	tests/regression/tools/streaming/Makefile
	tests/regression/tools/filtering/Makefile
	tests/regression/tools/health/Makefile
	tests/regression/tools/tracefile-limits/Makefile
	tests/regression/tools/snapshots/Makefile
	tests/regression/tools/live/Makefile
	tests/regression/tools/exclusion/Makefile
	tests/regression/tools/save-load/Makefile
	tests/regression/tools/save-load/configuration/Makefile
	tests/regression/tools/mi/Makefile
	tests/regression/tools/wildcard/Makefile
	tests/regression/tools/channel/Makefile
	tests/regression/tools/crash/Makefile
	tests/regression/tools/regen-metadata/Makefile
	tests/regression/tools/regen-statedump/Makefile
	tests/regression/tools/notification/Makefile
	tests/regression/tools/rotation/Makefile
	tests/regression/tools/base-path/Makefile
	tests/regression/tools/metadata/Makefile
	tests/regression/tools/tracker/Makefile
	tests/regression/tools/working-directory/Makefile
	tests/regression/tools/relayd-grouping/Makefile
	tests/regression/tools/clear/Makefile
	tests/regression/tools/trigger/Makefile
	tests/regression/tools/trigger/rate-policy/Makefile
	tests/regression/tools/trigger/start-stop/Makefile
	tests/regression/tools/trigger/utils/Makefile
	tests/regression/tools/trigger/name/Makefile
	tests/regression/tools/trigger/hidden/Makefile
	tests/regression/tools/context/Makefile
	tests/regression/tools/client/Makefile
	tests/regression/ust/Makefile
	tests/regression/ust/nprocesses/Makefile
	tests/regression/ust/high-throughput/Makefile
	tests/regression/ust/low-throughput/Makefile
	tests/regression/ust/before-after/Makefile
	tests/regression/ust/buffers-pid/Makefile
	tests/regression/ust/periodical-metadata-flush/Makefile
	tests/regression/ust/multi-session/Makefile
	tests/regression/ust/multi-lib/Makefile
	tests/regression/ust/overlap/Makefile
	tests/regression/ust/overlap/demo/Makefile
	tests/regression/ust/linking/Makefile
	tests/regression/ust/daemon/Makefile
	tests/regression/ust/exit-fast/Makefile
	tests/regression/ust/fork/Makefile
	tests/regression/ust/libc-wrapper/Makefile
	tests/regression/ust/baddr-statedump/Makefile
	tests/regression/ust/ust-dl/Makefile
	tests/regression/ust/java-jul/Makefile
	tests/regression/ust/java-log4j/Makefile
	tests/regression/ust/java-log4j2/Makefile
	tests/regression/ust/getcpu-override/Makefile
	tests/regression/ust/clock-override/Makefile
	tests/regression/ust/type-declarations/Makefile
	tests/regression/ust/rotation-destroy-flush/Makefile
	tests/regression/ust/blocking/Makefile
	tests/regression/ust/namespaces/Makefile
	tests/regression/ust/ust-constructor/Makefile
	tests/stress/Makefile
	tests/unit/Makefile
	tests/unit/ini_config/Makefile
	tests/perf/Makefile
	tests/utils/Makefile
	tests/utils/bt2_plugins/Makefile
	tests/utils/bt2_plugins/event_name/Makefile
	tests/utils/bt2_plugins/field_stats/Makefile
	tests/utils/lttngtest/Makefile
	tests/utils/tap/Makefile
	tests/utils/testapp/Makefile
	tests/utils/testapp/gen-data-pending/Makefile
	tests/utils/testapp/gen-ns-events/Makefile
	tests/utils/testapp/gen-kernel-test-events/Makefile
	tests/utils/testapp/gen-py-events/Makefile
	tests/utils/testapp/gen-ust-events/Makefile
	tests/utils/testapp/gen-ust-events-constructor/Makefile
	tests/utils/testapp/gen-ust-events-ns/Makefile
	tests/utils/testapp/gen-syscall-events-callstack/Makefile
	tests/utils/testapp/gen-ust-nevents/Makefile
	tests/utils/testapp/gen-ust-nevents-str/Makefile
	tests/utils/testapp/gen-syscall-events/Makefile
	tests/utils/testapp/gen-ust-tracef/Makefile
	tests/utils/testapp/userspace-probe-elf-binary/Makefile
	tests/utils/testapp/userspace-probe-elf-cxx-binary/Makefile
	tests/utils/testapp/userspace-probe-sdt-binary/Makefile
	tests/utils/xml-utils/Makefile
])

# Inject variable into python test script.
AC_CONFIG_FILES([tests/regression/ust/python-logging/test_python_logging],[chmod +x tests/regression/ust/python-logging/test_python_logging])
# Inject LTTNG_TOOLS_BUILD_WITH_LIBPFM variable in test script.
AC_CONFIG_FILES([tests/perf/test_perf_raw],[chmod +x tests/perf/test_perf_raw])
AC_CONFIG_FILES([tests/regression/ust/ust-dl/test_ust-dl],[chmod +x tests/regression/ust/ust-dl/test_ust-dl])
AC_CONFIG_FILES([pre-inst-env],[chmod +x pre-inst-env])

AC_OUTPUT

#
# Mini-report on what will be built.
#

PPRINT_INIT
PPRINT_SET_INDENT(1)
PPRINT_SET_TS(38)

AS_ECHO
AS_ECHO("${PPRINT_COLOR_BLDBLU}LTTng-tools $PACKAGE_VERSION \"$version_name\"$PPRINT_COLOR_RST")
AS_ECHO

AS_IF([test -n "$report_fold"], [
	AS_ECHO("`AS_ECHO("$version_description") | $report_fold -s`")
], [
	AS_ECHO("$version_description")
])

AS_ECHO
PPRINT_SUBTITLE([Features])

# Target architecture we're building for.
target_arch=$host_cpu
[
for f in $CFLAGS; do
        if test $f = "-m32"; then
			target_arch="32-bit"
        elif test $f = "-m64"; then
			target_arch="64-bit"
        fi
done
]
PPRINT_PROP_STRING([Target architecture], $target_arch)

# kmod enabled/disabled
test "x$with_kmod" != "xno" && value=1 || value=0
PPRINT_PROP_BOOL([libkmod support], $value)

# LTTng-UST enabled/disabled
test "x$with_lttng_ust" = "xyes" && value=1 || value=0
PPRINT_PROP_BOOL([LTTng-UST support], $value)

AS_ECHO
PPRINT_SUBTITLE([Libraries])

# liblttng-ctl enabled/disabled
test x$build_lib_lttng_ctl != xno && value=1 || value=0
PPRINT_PROP_BOOL([liblttng-ctl], $value)

AS_ECHO
PPRINT_SUBTITLE([Binaries])

# List binaries to be built
test x$enable_bin_lttng != xno && value=1 || value=0
PPRINT_PROP_BOOL([lttng], $value)

test x$enable_bin_lttng_consumerd != xno && value=1 || value=0
PPRINT_PROP_BOOL([lttng-consumerd], $value)

test x$enable_bin_lttng_crash != xno && value=1 || value=0
PPRINT_PROP_BOOL([lttng-crash], $value)

test x$enable_bin_lttng_relayd != xno && value=1 || value=0
PPRINT_PROP_BOOL([lttng-relayd], $value)

test x$enable_bin_lttng_sessiond != xno && value=1 || value=0
PPRINT_PROP_BOOL([lttng-sessiond], $value)

# Extras
test x$enable_extras != xno && value=1 || value=0
AS_ECHO
PPRINT_SET_INDENT(0)
PPRINT_PROP_BOOL([Extras], $value, $PPRINT_COLOR_SUBTITLE)
PPRINT_SET_INDENT(1)

AS_ECHO
PPRINT_SUBTITLE([Tests])

# Print clear message that tests won't be built
AS_IF([test "x$build_tests" = "xno"],[
	PPRINT_WARN([Tests won't be built since some binaries were disabled])
])

# LTTng UST Java agent JUL tests enabled/disabled
test "x$test_java_agent_jul" = "xyes" && value=1 || value=0
PPRINT_PROP_BOOL([LTTng-UST Java agent JUL tests], $value)

# LTTng UST Java agent Log4j 1.x tests enabled/disabled
test "x$test_java_agent_log4j" = "xyes" && value=1 || value=0
PPRINT_PROP_BOOL([LTTng-UST Java agent Log4j 1.x tests], $value)

# LTTng UST Java agent Log4j 2.x tests enabled/disabled
test "x$test_java_agent_log4j2" = "xyes" && value=1 || value=0
PPRINT_PROP_BOOL([LTTng-UST Java agent Log4j 2.x tests], $value)

test ! -z "$PYTHON2_AGENT" && value=1 || value=0
PPRINT_PROP_BOOL([LTTng-UST Python2 agent tests], $value)

test ! -z "$PYTHON3_AGENT" && value=1 || value=0
PPRINT_PROP_BOOL([LTTng-UST Python3 agent tests], $value)

# userspace-probe SDT instrumentation tests enabled/disabled
test "x$test_sdt_uprobe" = "xyes" && value=1 || value=0
PPRINT_PROP_BOOL([LTTng-modules SDT uprobe tests], $value)

#Python binding enabled/disabled
test "x$enable_python_binding" = xyes && value=1 || value=0
AS_ECHO
PPRINT_SET_INDENT(0)
PPRINT_PROP_BOOL([Python binding], $value, $PPRINT_COLOR_SUBTITLE)

# man pages build enabled/disabled
m4_pushdef([build_man_pages_msg], [Build and install man pages])

AS_IF([test "x$man_pages_opt" != "xno"], [
	AS_IF([test "x$in_git_repo" = "xyes"], [
		PPRINT_PROP_BOOL([build_man_pages_msg], 1, $PPRINT_COLOR_SUBTITLE)
	], [
		AS_IF([test "x$have_asciidoc_xmlto" = "xyes"], [
			PPRINT_PROP_BOOL([build_man_pages_msg], 1, $PPRINT_COLOR_SUBTITLE)
		], [
			PPRINT_PROP_STRING([build_man_pages_msg],
				[${PPRINT_COLOR_BLDGRN}yes (already built)],
				$PPRINT_COLOR_SUBTITLE)
		])
	])
], [
	PPRINT_PROP_BOOL([build_man_pages_msg], 0, $PPRINT_COLOR_SUBTITLE)
])

m4_popdef([build_man_pages_msg])

test "x$embedded_help" = xyes && value=1 || value=0
PPRINT_PROP_BOOL([Embed --help messages], $value, $PPRINT_COLOR_SUBTITLE)

test "x$api_doc" = xyes && value=1 || value=0
PPRINT_PROP_BOOL([liblttng-ctl HTML API documentation], $value, $PPRINT_COLOR_SUBTITLE)

PPRINT_SET_INDENT(1)

report_bindir="`eval eval echo $bindir`"
report_libdir="`eval eval echo $libdir`"

# Print the bindir and libdir this `make install' will install into.
AS_ECHO
PPRINT_SUBTITLE([Install directories])
PPRINT_PROP_STRING([Binaries], [$report_bindir])
PPRINT_PROP_STRING([Libraries], [$report_libdir])

AS_ECHO
PPRINT_SUBTITLE([Search directories])

# If we build the sessiond, print the paths it will use
AS_IF([test "$SESSIOND_BIN" = ""],[
	path="$report_bindir/lttng-sessiond"
],[
	path="$SESSIOND_BIN"
])
PPRINT_PROP_STRING([lttng-sessiond executable], [$path])

AS_IF([test "$CONSUMERD32_BIN" = ""],[
	path="`eval eval echo $lttnglibexecdir`/lttng-consumerd"
],[
	path="$CONSUMERD32_BIN"
])
PPRINT_PROP_STRING([32-bit lttng-consumerd executable], [$path])

AS_IF([test "$CONSUMERD32_LIBDIR" = ""],[
	path="`eval eval echo $libdir`"
],[
	path="$CONSUMERD32_LIBDIR"
])
PPRINT_PROP_STRING([32-bit consumer libraries], [$path])

AS_IF([test "$CONSUMERD64_BIN" = ""],[
	path="`eval eval echo $lttnglibexecdir`/lttng-consumerd"
],[
	path="$CONSUMERD64_BIN"
])
PPRINT_PROP_STRING([64-bit lttng-consumerd executable], [$path])

AS_IF([test "$CONSUMERD64_LIBDIR" = ""],[
	path="`eval eval echo $libdir`"
],[
	path="$CONSUMERD64_LIBDIR"
])
PPRINT_PROP_STRING([64-bit consumer libraries], [$path])
PPRINT_SET_INDENT(0)

AS_IF([test "x$warn_prebuilt_man_pages" = "xyes" ], [
	AS_ECHO
	PPRINT_WARN([You need asciidoc and xmlto to build the LTTng-tools man pages.

Note that the man pages are already built in this distribution tarball,
therefore asciidoc and xmlto are only needed if you intend to modify
their sources.

Also note that the installed man pages will contain the project's
default command-line option and environment variable values.

Use --disable-man-pages to completely disable building and installing
the man pages.])
])
